package 课程设计报告_hb_7_8;

/**
 * @author Jiang Zhiyan
 *
 * 2021年7月8日 上午11:18:24
 *
 */
public class AddMoneyThread extends Thread{
	  private Account account;
	   private double money;
	   
	/**
	 * @param account
	 * @param money
	 */
	public AddMoneyThread(String name,Account account, double money) {
		super(name);
		this.account = account;
		this.money = money;
	}
	 
	@Override
		public void run() {
//		account称为同步监视器
		  synchronized (account) {
			  try {
					Thread.sleep(2);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				System.out.println(Thread.currentThread().getName());
				account.addMoney(money);
			}
		}	
		
}
